<template>
    <div class="box">
        <van-address-list v-model="chosenAddressId" :list="list" default-tag-text="默认" @add="onAdd" @edit="onEdit"
            add-button-text="￥4000.00 去支付" />
    </div>
</template>

<script setup>
import { ref } from 'vue';
import { showToast } from 'vant';

import { payApi } from '@/api/api';

const chosenAddressId = ref('1');
const list = [
    {
        id: '1',
        name: '张三',
        tel: '13000000000',
        address: '浙江省杭州市西湖区文三路 138 号东方通信大厦 7 楼 501 室',
        isDefault: true,
    },
    {
        id: '2',
        name: '李四',
        tel: '1310000000',
        address: '浙江省杭州市拱墅区莫干山路 50 号',
    },
];

import _ from "lodash"

const onAdd = _.debounce(() => {
    let obj = {
        orderId: "31232132",
        subject: "收到上档次撒首都首都大方",
        totalPrice: "4000"
    }
    payApi(obj).then((res) => {
        console.log(res)
        if (res.data.code == 0) {
            window.open(res.data.data,"_blank")
        }
    })
    console.log(123)
}, 150)
const onEdit = (item, index) => showToast('编辑地址:' + index);

</script>

<style lang="scss" scoped>
.box {
    width: 100%;
    height: 100%;
}
</style>